package com.samebuilding.util;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.samebuilding.domain.User;

public class OnlineListener implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent event) {
    	
    }
    public void sessionDestroyed(HttpSessionEvent event) {

       	User u = (User)event.getSession().getAttribute("user");
       	if(u != null) {
       		ServletContext application = event.getSession().getServletContext();
           	synchronized(application){
           		List onlineUser = (List)application.getAttribute("onlineUser");
        	
        		if(u!=null){
            		onlineUser.remove(u);
            	}
            	application.setAttribute("onlineUser", onlineUser);
        	}
       	}
       	
    	
    }
}
